// @charset "utf-8";

define(function(require, exports, module) {
	var publicMethod = require('../public/public'),
		clientApi = require('../public/clientapi'),
		clientStorage = require('../public/storage');

	function resizeDebounce(method, context) {
		clearTimeout(method.tId);
		method.tId = setTimeout(function() {
			method.call(context);
		}, 300);
	}
	var resetSize = {
		chatScrollBar: null,
		init: function() {

			var self = this;
			var theHeight = self.changeSize();

			// $(window).resize(function() {
			// 	setTimeout(function () {
			// 		self.changeSize();
			// 	}, 200);
			// });
			$(window).resize(function () {
				resizeDebounce(self.changeSize, self)
			});

			this.chatScrollBar = $('#modules-list').slimscroll({
				size: '7px',
				width: 'auto',
				height: theHeight,
				alwaysVisible: true,
				disableFadeOut: true,
				color: '#34373c',
				distance: '1px',
				// railColor: '#adadad',
				opacity: 1,
				railVisible: false,
				wheelStep: 20
			});

			$('#robot-switch').on('click', function () {
				var $robotMod = $('#robot-module'),
					$systemMod = $('#modules-list, #modules-list-ul');
				if ($robotMod.is(':visible')) {
					$robotMod.hide();
					var windowWidth = $(window).width();
					$systemMod.width(windowWidth - 10- 2);
				} else {
					self.changeSize(true);
					$robotMod.show();
				}

			});
		},
		changeSize: function(isSwitch) {
			var windowWidth = $(window).width(),
				windowHeight = $(window).height();
			var bodyWidth = windowWidth > 1260 ? windowWidth : 1260,
				bodyHeight = windowHeight > 520 ? windowHeight : 520; //750

			var $robotMod = $('#robot-module'),
				$systemMod = $('#modules-list, #modules-list-ul');
			$('#container').height(bodyHeight).width(bodyWidth);
			$('.robot-main, .robot-main .scroll-wrap').height(bodyHeight -28 - 41- 28 - 44);

			var widthTmp = 1248;
			if (bodyWidth >= 1675) {
				$robotMod.width(bodyWidth - 1248 - 10 - 2).height(bodyHeight - 28);
			} else {
				$robotMod.width(bodyWidth - 832 -10 - 2).height(bodyHeight - 28);
				widthTmp = 832;
			}
			if (!isSwitch && $robotMod.is(':hidden')) {
				widthTmp = bodyWidth - 10 - 2;
			}
			$('#system-module-box, #add-history-box').height(bodyHeight - 28 -28);
			$systemMod.width(widthTmp).height(bodyHeight - 28);

			theHeight = bodyHeight - 28 > 520 ?  bodyHeight - 28 : 520;
			return theHeight;
		}
	};

	module.exports = resetSize;
});